
#ifndef __DICTIONARY_H
#define __DICTIONARY_H

#include "trie.h"
#include "../util.h"


class Dictionary
{
public:
	enum DictionaryType { FMM=0x0DCA0001, RMM=0x0DCA000};
private:
    Trie* trie;
	DictionaryType type;

public:
	Dictionary(const char* dict_file,DictionaryType dictType);
	~Dictionary();
	
    /**
     * re-construct this dictionary from a  "dictionary" text file 
     */
    void loadDict(const char* dict);
	
    /**
     * find out whether string end with 0 is in dictionary.
     */
	bool search(wchar_t *key);

	/**
	 * find out wheter string with specific length is existing in dictionary.
	 */
	bool search(wchar_t *key, int length);

	/**
	 * retrive
	 */
	
	int forward(int base, wchar_t w);
	bool is_phrase(int pos){
		return trie->is_final(pos);
	}
	
	void info();

	void saveAsBin(const char * path);
private:
	/**
	 * add a new phrase into dictionary
	 */
	bool add(wchar_t *key);

	void loadFromBin(const char * path);
};
#endif


